[%# -*- mode: html -*- %]
[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Erik Stambaugh <erik@dasbistro.com>
  #%]

[%# INTERFACE:
  # events: hash, keyed by event_id number.  Values are anonymous hashes of:
  #     schedule: array of hashes containing schedule info:
  #         day:    value in day column
  #         time:   value selected in time column
  #         mailto_type: 0=user 1=group
  #         mailto: recipient's id (profile or group)
  #     queries:  as with schedule, an anonymous array containing hashes of:
  #         name:  the named query's name
  #         title: title to be displayed on the results
  #         sort:  integer that sets execution order on named queries
  #%]

[% PROCESS global/variables.none.tmpl %]

[% title = "设定订阅" %]
[% PROCESS global/header.html.tmpl
  title = title
  doc_section = "whining.html"
%]

<p>
  “订阅”这项功能，是 [% terms.Bugzilla %] 在一个固定的期间执行一项已储存的搜寻，并将搜寻结果所列出的 [% terms.bugs %] 以电子邮件传送。
</p>

<p>
  要设定一个新的订阅事件，点选“新增事件”。
  <br>只要输入信件主旨以及描述文字，就会和[% terms.bug %]清单一起寄出。
</p>

<p>
  要替事件设定排程，点选“新增排程”。
  <br>排程的内容包括一天、一天中的某个时间，或是一个时间的间隔（例如每15分钟），以及电子邮件地址。
  <br>电子邮件地址将会根据你的权限来决定是否可以变动。
  <br>一个事件可以设定多组排程，以便对不同的使用者执行多次。
</p>

<p>
  搜寻来自已储存的搜寻。
  <br>已储存的搜寻是在执行<a href="query.cgi">搜寻</a>页面，并将该页面结果以指定的名称储存于 [% terms.Bugzilla %] 中。
  <br>点选“新增搜寻”，选择已储存的搜寻名称，并于 [% terms.bug %] 表格中加入标题。
  <br>“排序”下的数字为选填。若有多笔搜寻排列，将会以该数字决定执行的顺序（从最小到最大）。
  <br>如果勾选“每个 [% terms.bug %] 送出一封信”，那么符合该搜寻的每个 [% terms.bug%] 都会寄出一封信。
</p>

<p>
  所有时间为伺服器端时间 ([% local_timezone FILTER html %]) 。
</p>

<form method="post" action="editwhines.cgi">
[%# This hidden submit button must be here to set default behavior when
    the user presses return on a form input field #%]
<input type="submit" value="更新／送出" name="commit"
       style="display: none;" id="commit">
<input type="hidden" name="update" value="1">
<input type="hidden" name="token" value="[% token FILTER html %]">

[% FOREACH event = events %]

<table cellspacing="2" cellpadding="2" style="border: 1px solid;">
  <tr>
    <th align="left">
      事件：
    </th>
    <td align="right" colspan="2">
      <input type="submit" value="删除事件"
             name="remove_event_[% event.key %]"
             id="remove_event_[% event.key %]">
    </td>
  </tr>

  <tr>
    <td valign="top" align="right">
      电子邮件主旨：
    </td>
    <td colspan="2">
      <input type="text" name="event_[% event.key %]_subject"
             size="60" maxlength="128" value="
             [%- event.value.subject FILTER html %]">
    </td>
  </tr>

  <tr>
    <td valign="top" align="right">
      在订阅讯息中的描述文字：
    </td>
    <td colspan="2">
      [% INCLUDE global/textarea.html.tmpl
         name           = "event_${event.key}_body"
         minrows        = 3
         maxrows        = 10
         defaultrows    = 5
         cols           = 80
         defaultcontent = event.value.body
       %]
    </td>
  </tr>

  <tr>
    <td valign="top" align="right">
      即使搜寻结果没有任何 [% terms.bugs %] ，仍然送出讯息：
    </td>
    <td colspan="2">
      <input type="checkbox" name="event_[% event.key %]_mailifnobugs"
        [%- IF event.value.mailifnobugs == 1 %] checked [% END %]>
    </td>
  </tr>

  [% IF event.value.schedule.size == 0 %]

    <tr>
      <td valign="top" align="right">
        排程：
      </td>
      <td class="unset" colspan="2">
        无任何排程可执行<br>
        <input type="submit" value="新增排程"
               name="add_schedule_[% event.key %]"
               id="add_schedule_[% event.key %]">
      </td>
    </tr>

  [% ELSE %]

    <tr>
      <td valign="top" align="right">
        排程：
      </td>
      <td class="set" colspan="2">

        <table>
          <tr>
            <th>
              执行间隔
            </th>
            <th>
              [% IF mail_others %]
                寄电子邮件到
              [% END %]
            </th>
            <th>
            </th>
          </tr>
          [% FOREACH schedule = event.value.schedule %]
            <tr>
              <td align="left">

                [%# these hidden fields allow us to compare old values instead
                    of reading the database to tell if a field has changed %]

                <input type="hidden" value="[% schedule.day FILTER html %]"
                       name="orig_day_[% schedule.id %]">
                <input type="hidden" value="[% schedule.time FILTER html %]"
                       name="orig_time_[% schedule.id %]">
                [% PROCESS day_field val=schedule.day %]
                [% PROCESS time_field val=schedule.time %]
              </td>
              <td align="left">
                [% IF mail_others %]
                  <input type="hidden" name="orig_mailto_type_[% schedule.id %]"
                         value="[% schedule.mailto_type FILTER html %]">
                  <select name="mailto_type_[% schedule.id %]">
                    <option value="0" [% IF schedule.mailto_type == 0 %]
                                        selected
                                      [% END %]>使用者</option>
                    <option value="1" [% IF schedule.mailto_type == 1 %]
                                        selected
                                      [% END %]>群组</option>
                  </select>
                  <input type="hidden" name="orig_mailto_[% schedule.id %]"
                         value="[% schedule.mailto FILTER html %]">
                  <input type="text" name="mailto_[% schedule.id %]"
                         value="[% schedule.mailto FILTER html %]" size="30">
                [% END %]
              </td>
              <td align="left">
                <input type="submit" value="删除"
                       name="remove_schedule_[% schedule.id %]"
                       id="remove_schedule_[% schedule.id %]">
              </td>
            </tr>
          [% END %]

          <tr>
            <td colspan="3">
              <input type="submit" value="新增排程"
                     name="add_schedule_[% event.key %]"
                     id="add_schedule_[% event.key %]">
            </td>
          </tr>

        </table>

      </td>
    </tr>

  [% END %]

  [% IF event.value.queries.size == 0 %]

    <tr>
      <td valign="top" align="right">
        搜寻：
      </td>
      <td align="left">
        无搜寻<br>
        <input type="submit" value="新增搜寻"
               name="add_query_[% event.key %]"
               id="add_query_[% event.key %]">
      </td>
      <td align="right" valign="bottom">
        <input type="submit" value="更新／送出" name="commit" id="update">
      </td>
    </tr>

  [% ELSE %]

    <tr>
      <td valign="top" align="right">
        搜寻：
      </td>
      <td align="left" colspan="2">

        <table>
          <tr>
            <th>排序</th>
            <th>搜寻</th>
            <th>标题</th>
            <th></th>
            <th></th>
          </tr>

          [% FOREACH query = event.value.queries %]

            <tr>
              <td align="left">
                <input type="text" name="query_sort_[% query.id %]"
                       size="3" value="[% query.sort %]">
                <input type="hidden" value="[% query.sort %]"
                       name="orig_query_sort_[% query.id %]">
              </td>
              <td align="left">
                <input type="hidden" value="[% query.name FILTER html %]"
                       name="orig_query_name_[% query.id %]">
                [% PROCESS query_field thisquery=query.name %]
              </td>
              <td align="left">
                <input type="hidden" value="[% query.title FILTER html %]"
                       name="orig_query_title_[% query.id %]">
                <input type="text" name="query_title_[% query.id %]"
                       size="50" value="[% query.title FILTER html %]"
                       maxlength="64">
              </td>
              <td align="left">
                <input type="hidden" value="[% query.onemailperbug FILTER html %]"
                       name="orig_query_onemailperbug_[% query.id %]">
                <input type="checkbox" [% IF query.onemailperbug == 1 %] checked [% END %]
                       id="query_onemailperbug_[% query.id %]"
                       name="query_onemailperbug_[% query.id %]">
                <label for="query_onemailperbug_[% query.id %]">每个 [% terms.bug %] 送出一封信</label>
              </td>
              <td align="right">
                <input type="submit" value="删除"
                       name="remove_query_[% query.id %]"
                       id="remove_query_[% query.id %]">
              </td>
            </tr>

          [% END %]

          <tr>
            <td colspan="3">
              <input type="submit" value="新增搜寻"
                     name="add_query_[% event.key %]"
                     id="add_query_[% event.key %]">
            </td>
            <td align="right" colspan="2">
              <input type="submit" value="更新／送出" name="commit" id="update">
            </td>
          </tr>
        </table>

      </td>
    </tr>

  [% END %]

</table>

[% END %]

<p align="left">
  <input type="submit" value="新增事件" name="add_event" id="add_event">
</p>

</form>

[% PROCESS global/footer.html.tmpl %]

[% BLOCK query_field +%]

  [% IF available_queries.size > 0 %]

    <select name="query_name_[% query.id %]">
      [% FOREACH q = available_queries %]
        <option [% "selected" IF q == thisquery %] value="[% q FILTER html %]">
            [% q FILTER html %]
        </option>
      [% END %]
    </select>

  [% ELSE %]
    请浏览<a href="query.cgi">搜寻</a>页面并储存搜寻结果
  [% END %]

[%+ END %]

[% BLOCK day_field +%]
  <select name="day_[% schedule.id %]">
      [%
        options = [
            ['All',  '每天',         ],
            ['MF',   '星期一至五',   ],
            ['Sun',  '星期日',       ],
            ['Mon',  '星期一',       ],
            ['Tue',  '星期二',       ],
            ['Wed',  '星期三',       ],
            ['Thu',  '星期四',       ],
            ['Fri',  '星期五',       ],
            ['Sat',  '星期六',       ],
            ['1',    '每月1日',      ],
            ['2',    '每月2日',      ],
            ['3',    '每月3日',      ],
            ['4',    '每月4日',      ],
            ['5',    '每月5日',      ],
            ['6',    '每月6日',      ],
            ['7',    '每月7日',      ],
            ['8',    '每月8日',      ],
            ['9',    '每月9日',      ],
            ['10',   '每月10日',     ],
            ['11',   '每月11日',     ],
            ['12',   '每月12日',     ],
            ['13',   '每月13日',     ],
            ['14',   '每月14日',     ],
            ['15',   '每月15日',     ],
            ['16',   '每月16日',     ],
            ['17',   '每月17日',     ],
            ['18',   '每月18日',     ],
            ['19',   '每月19日',     ],
            ['20',   '每月20日',     ],
            ['21',   '每月21日',     ],
            ['22',   '每月22日',     ],
            ['23',   '每月23日',     ],
            ['24',   '每月24日',     ],
            ['25',   '每月25日',     ],
            ['26',   '每月26日',     ],
            ['27',   '每月27日',     ],
            ['28',   '每月28日',     ],
            ['29',   '每月29日',     ],
            ['30',   '每月30日',     ],
            ['31',   '每月31日',     ],
            ['last', '每月最后一日', ],
        ]
      %]

      [% FOREACH option = options %]
        <option value="[% option.0 %]"
                [%- IF val == option.0 +%] selected[% END %]>
                [%- option.1 -%]
        </option>
      [% END %]

  </select>
[%+ END %]

[% BLOCK time_field +%]
<select name="time_[% schedule.id %]">

  [%
    options = [
        [ '0',     '00:00',    ],
        [ '1',     '01:00',    ],
        [ '2',     '02:00',    ],
        [ '3',     '03:00',    ],
        [ '4',     '04:00',    ],
        [ '5',     '05:00',    ],
        [ '6',     '06:00',    ],
        [ '7',     '07:00',    ],
        [ '8',     '08:00',    ],
        [ '9',     '09:00',    ],
        [ '10',    '10:00',    ],
        [ '11',    '11:00',    ],
        [ '12',    '12:00',    ],
        [ '13',    '13:00',    ],
        [ '14',    '14:00',    ],
        [ '15',    '15:00',    ],
        [ '16',    '16:00',    ],
        [ '17',    '17:00',    ],
        [ '18',    '18:00',    ],
        [ '19',    '19:00',    ],
        [ '20',    '20:00',    ],
        [ '21',    '21:00',    ],
        [ '22',    '22:00',    ],
        [ '23',    '23:00',    ],
        [ '60min', '每小时',   ],
        [ '30min', '每30分钟', ],
        [ '15min', '每15分钟', ],
    ]
  %]

      [% FOREACH option = options %]
        <option value="[% option.0 %]"
                [%- IF val == option.0 +%] selected[% END %]>
                [%- option.1 -%]
        </option>
      [% END %]

</select>

[%+ END %]

